/*     */ package com.newcrm.webapi;
/*     */ 
/*     */ import com.newcrm.bean.ProductInfo;
/*     */ import com.newcrm.config.Config;
/*     */ import com.newcrm.config.MyDBSetting;
/*     */ import com.newcrm.db.ConnectionManager;
/*     */ import com.newcrm.db.UserManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.ParameterUtil;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.sub.ActiveCodeChecker;
/*     */ import com.newcrm.webapi.sub.CreateDatabase;
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.net.URLEncoder;
/*     */ import javax.servlet.RequestDispatcher;
/*     */ import javax.servlet.ServletConfig;
/*     */ import javax.servlet.ServletContext;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ 
/*     */ public class Setup extends HttpServlet
/*     */ {
/*     */   private static final long serialVersionUID = 1849093944149188625L;
/*     */   private static final String URL_KEY = "setup";
/*  35 */   private static Logger logger = Logger.getLogger(Setup.class.getName());
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  51 */     String url = request.getRequestURI();
/*  52 */     String[] param = ParameterUtil.getParameters(url, "setup");
/*     */ 
/*  54 */     Config config = Config.getInstance();
/*     */ 
/*  56 */     if ((param == null) || (param.length == 0))
/*     */     {
/*  58 */       String type = Util.getURLParameter(request.getParameter("type"));
/*  59 */       if ((type != null) && (type.trim().length() > 0))
/*     */       {
/*  61 */         UserManager manager = new UserManager();
/*  62 */         boolean flag = manager.isInstalled();
/*  63 */         if (flag) {
/*  64 */           response.sendRedirect(request.getContextPath() + "/");
/*  65 */           return;
/*     */         }
/*     */       }
/*     */ 
/*  69 */       File lockFile = new File(getServletContext().getRealPath(
/*  70 */         "sql/setup.lock"));
/*     */ 
/*  72 */       if (lockFile.exists()) {
/*  73 */         request.setAttribute("filepath", lockFile.getAbsolutePath());
/*  74 */         getServletConfig().getServletContext()
/*  75 */           .getRequestDispatcher("/setuplock.jsp")
/*  76 */           .forward(request, response);
/*  77 */         return;
/*     */       }
/*     */ 
/*  81 */       getServletConfig().getServletContext()
/*  82 */         .getRequestDispatcher("/" + config.productInfo.setupFile)
/*  83 */         .forward(request, response);
/*     */ 
/*  85 */       return;
/*     */     }
/*     */ 
/*  88 */     if ("activeCode".equals(param[0])) {
/*     */       try {
/*  90 */         new ActiveCodeChecker().parse(request, response);
/*     */       } catch (NotFoundException localNotFoundException1) {
/*     */       }
/*  93 */       return;
/*     */     }
/*     */ 
/*  96 */     if ("step1".equals(param[0])) {
/*  97 */       getServletConfig().getServletContext()
/*  98 */         .getRequestDispatcher("/setupstep1.jsp")
/*  99 */         .forward(request, response);
/* 100 */       return;
/*     */     }
/*     */ 
/* 103 */     if ("step2".equals(param[0])) {
/* 104 */       String activeCode = Util.getURLParameter(request
/* 105 */         .getParameter("activeCode"));
/* 106 */       String companyId2 = Util.getURLParameter(request
/* 107 */         .getParameter("companyId2"));
/* 108 */       String checkCode = Util.getURLParameter(request
/* 109 */         .getParameter("checkCode"));
/* 110 */       String licenceNum = Util.getURLParameter(request
/* 111 */         .getParameter("licenceNum"));
/* 112 */       String expiredDate = Util.getURLParameter(request
/* 113 */         .getParameter("expiredDate"));
/*     */ 
/* 115 */       String dbIp = Util.getURLParameter(request.getParameter("dbIp"));
/* 116 */       String dbPort = 
/* 117 */         Util.getURLParameter(request.getParameter("dbPort"));
/* 118 */       String dbName = 
/* 119 */         Util.getURLParameter(request.getParameter("dbName"));
/*     */ 
/* 121 */       String dbUser = 
/* 122 */         Util.getURLParameter(request.getParameter("dbUser"));
/* 123 */       String dbPassword = Util.getURLParameter(request
/* 124 */         .getParameter("dbPassword"));
/*     */ 
/* 126 */       String companyName = Util.getURLParameter(request
/* 127 */         .getParameter("companyName"));
/* 128 */       String userId = 
/* 129 */         Util.getURLParameter(request.getParameter("userId"));
/* 130 */       String userName = Util.getURLParameter(request
/* 131 */         .getParameter("userName"));
/* 132 */       String userPassword = Util.getURLParameter(request
/* 133 */         .getParameter("userPassword"));
/* 134 */       String email = Util.getURLParameter(request.getParameter("email"));
/* 135 */       String agent = Util.getURLParameter(request.getParameter("agent"));
/* 136 */       String tel = Util.getURLParameter(request.getParameter("tel"));
/* 137 */       String qq = Util.getURLParameter(request.getParameter("qq"));
/*     */ 
/* 139 */       request.setAttribute("activeCode", activeCode);
/* 140 */       request.setAttribute("companyId2", companyId2);
/* 141 */       request.setAttribute("checkCode", checkCode);
/* 142 */       request.setAttribute("licenceNum", licenceNum);
/* 143 */       request.setAttribute("expiredDate", expiredDate);
/*     */ 
/* 145 */       request.setAttribute("dbIp", dbIp);
/* 146 */       request.setAttribute("dbPort", dbPort);
/* 147 */       request.setAttribute("dbName", dbName);
/* 148 */       request.setAttribute("dbUser", dbUser);
/* 149 */       request.setAttribute("dbPassword", dbPassword);
/* 150 */       request.setAttribute("companyName", companyName);
/* 151 */       request.setAttribute("userId", userId);
/* 152 */       request.setAttribute("userName", userName);
/* 153 */       request.setAttribute("userPassword", userPassword);
/* 154 */       request.setAttribute("email", email);
/*     */       try
/*     */       {
/* 158 */         String webUrl = "http://tj.qikebao.com/log?t=new&name=" + 
/* 159 */           URLEncoder.encode(companyName, "utf-8") + "&tel=" + 
/* 160 */           URLEncoder.encode(tel, "utf-8") + "&agent=" + 
/* 161 */           URLEncoder.encode(agent, "utf-8") + "&contact=" + 
/* 162 */           URLEncoder.encode(userName, "utf-8") + "&email=" + 
/* 163 */           URLEncoder.encode(email, "utf-8") + "&qq=" + 
/* 164 */           URLEncoder.encode(qq, "utf-8");
/* 165 */         Jsoup.connect(webUrl)
/* 166 */           .userAgent(
/* 167 */           "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; Tablet PC 2.0)")
/* 168 */           .timeout(10000).get();
/*     */       } catch (Exception e) {
/* 170 */         logger.warn("failed");
/*     */       }
/* 172 */       getServletConfig().getServletContext()
/* 173 */         .getRequestDispatcher("/setupstep2.jsp")
/* 174 */         .forward(request, response);
/* 175 */       return;
/*     */     }
/*     */ 
/* 178 */     if ("finish".equals(param[0]))
/*     */     {
/* 180 */       File lockFile = new File(getServletContext().getRealPath(
/* 181 */         "sql/setup.lock"));
/* 182 */       if ((!lockFile.exists()) && 
/* 183 */         (!lockFile.createNewFile())) {
/* 184 */         throw new IOException("can not create file by io exception");
/*     */       }
/*     */ 
/* 189 */       File needFile = new File(getServletContext().getRealPath(
/* 190 */         "sql/upgradeSQL.need"));
/* 191 */       if (needFile.exists())
/*     */         try {
/* 193 */           needFile.delete();
/*     */         }
/*     */         catch (SecurityException localSecurityException)
/*     */         {
/*     */         }
/* 198 */       getServletContext().setAttribute(
/* 199 */         "needUpgradeSQL", "0");
/*     */ 
/* 201 */       getServletConfig().getServletContext()
/* 202 */         .getRequestDispatcher("/setupfinish.jsp")
/* 203 */         .forward(request, response);
/* 204 */       return;
/*     */     }
/* 206 */     if ("database".equals(param[0])) {
/* 207 */       AbstractAction action = new CreateDatabase(getServletContext());
/*     */       try {
/* 209 */         action.parse(request, response);
/*     */       } catch (NotFoundException e) {
/* 211 */         logger.warn(e);
/*     */       }
/* 213 */       return;
/*     */     }
/*     */ 
/* 217 */     if ("reloadDBSetting".equals(param[0])) {
/* 218 */       MyDBSetting.init();
/* 219 */       ConnectionManager.reConnect();
/* 220 */       getServletConfig().getServletContext()
/* 221 */         .getRequestDispatcher("/login.jsp")
/* 222 */         .forward(request, response);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void doPost(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/* 240 */     doGet(request, response);
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.Setup
 * JD-Core Version:    0.6.1
 */